<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2018/4/2
  Time: 16:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>userAdd</title>
</head>
<body>
<%@ include file="isLogin.jsp" %>
<p><a href="userList.jsp">返回列表</a></p><br/>
<form action="#" method="post">
    用户名：<input type="text" name="username"/><br/>
    密码：<input type="text" name="password"/><br/>
    <input type="submit" value="添加"/>

</form>
<%
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    if ((username != null) && (password != null)) {
        Connection connection = null;
        Statement statement = null;
//    ResultSet resultSet = null;

        String sql = "INSERT into t_users(username,password) values('" + username + "','" + password + "')";

        Class.forName("com.mysql.jdbc.Driver");

        connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone = UTC",
                "root",
                "123456"
        );

        statement = connection.createStatement();
        statement.executeUpdate(sql);

//    resultSet.close();
        statement.close();
        connection.close();
    }
%>

<jsp:include page="footer.jsp">
    <jsp:param name="year" value="2018"/>
</jsp:include>

</body>
</html>
